package com.fivefu.core.hik.services.impl;

import com.fivefu.base.common.utils.str.StrUtils;
import com.fivefu.core.hik.entity.DbHikVehicleCamera;
import com.fivefu.core.hik.mapper.DbHikVehicleCameraMapper;
import com.fivefu.core.hik.services.DbHikVehicleCameraService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fivefu.module.dictionary.entity.DbSysDict;
import com.fivefu.module.dictionary.service.DbSysDictService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 海康车辆监控点关联表 服务实现类
 * </p>
 *
 * @author 
 * @since 2022-09-01 18:03:33
 */
@Service
public class DbHikVehicleCameraServiceImpl extends ServiceImpl<DbHikVehicleCameraMapper, DbHikVehicleCamera> implements DbHikVehicleCameraService {

    @Resource
    private DbSysDictService dbSysDictService;

    /**
     * 编辑海康车辆监控点关联信息
     * @param vehicleCamera 海康车辆监控点关联表对象
     */
    @Override
    public void editHikCamera(DbHikVehicleCamera vehicleCamera) {

        //判断视频通道类型是否为空
        if (StrUtils.isNotNull(vehicleCamera.getChannelType())) {
            DbSysDict dict = dbSysDictService.queryDictByValue("CH", vehicleCamera.getChannelType());
            if(dict != null){
                vehicleCamera.setChannelType(dict.getDictCode());
            }
        }
        //车辆监控点关联id不为空则为更新
        if (null != vehicleCamera.getId()) {
            baseMapper.updateById(vehicleCamera);
        } else {
            baseMapper.insert(vehicleCamera);
        }
    }

}
